<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/commons/jsp/taglibs.jsp"%>
<table id="bindUserTable" class="easyui-datagrid" 
	data-options="singleSelect:false,toolbar:'#bindUsertb',method:'post',rownumbers:true,fit:true,fitColumns:true,border:false,
		pagination:true,remoteSort:true,multiSort:true,striped:true,onLoadSuccess:function(data){$('#'+paramObj.searchID).attr('disabled',false);},
		url:'${ctx}/framework/user/roleUsers?roleId=${param.roleId}&roleUser=true'"}>
	<thead>
		<tr>
			<th data-options="field:'id',checkbox:true"></th>
			<th data-options="field:'name',width:40,sortable:true,halign:'center'">姓名</th>
			<th data-options="field:'loginName',width:40,halign:'center'">登录名称</th>
			<th data-options="field:'deptName',width:80,halign:'center'">部门</th>
			<th data-options="field:'lastLoginTime',width:80" align="center">最后登录时间</th>
		</tr>
	</thead>
</table>
<div id="bindUsertb">
	<div>
		<a href="javascript:void(0);" onclick="addBindUserDialog();" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加绑定用户</a>
		<a href="javascript:void(0);" onclick="deleteBindUserDialog();" class="easyui-linkbutton" iconCls="icon-remove" plain="true">取消绑定用户</a>
	</div>
</div>
<script type="text/javascript">
	function deleteBindUserDialog(){
		var records = $('#bindUserTable').datagrid('getSelections');
		if(records.length < 1){
			$.messager.alert('提示',"请选择记录！",'info');
		}else{
			var userIds = '';
			for(var i=0;i<records.length;i++){
				if(i == 0){
					userIds += records[i].id;
				}else{
					userIds += ','+records[i].id;
				}
			}
			$.messager.confirm('提示',"你确定取消绑定这些记录吗？",function(result){
				$.ajax({
					type: "get",
					timeout:20000,
					url:  "${ctx}/framework/role/removeBindUser",
					data:{"deleteIds":userIds,"id":'${param.roleId}'},
					success: function(data){
						var msn = ''||i18n[''];
						msn = msn||i18n[data];	
						if(msn == undefined){
							$.messager.alert('提示',i18n.serverError,'info');
						}else if(msn)	{	
							$.messager.alert('提示',msn,'info',function(){$('#bindUserTable').datagrid('reload');});
						}
					},
					error: function(){
						$.messager.alert('提示',i18n.requestError,'error');
					}
				});
			});
		}
	}

	function addBindUserDialog(){
		$('#addBindUserDialog').dialog({    
		    title:"添加绑定用户",  
		    iconCls:'icon-user-menu',
		    width: 600,    
		    zIndex:100,
		    height: 350,    
		    closed: false,    
		    inline : true,
		    cache: false,    
		    href: "${ctx}/framework/role/add-bind-user.jsp?roleId=${param.roleId}",    
		    modal: true,
		    buttons : [{text:'确定',
			    		id:'saveEntityBt',
						iconCls:'icon-ok',
						handler:function(){
			    			var records = $('#addBindUserTable').datagrid('getSelections');
			    			if(records.length < 1){
								$.messager.alert('提示',"请选择绑定的用户！",'info');
							}else{
								var userIds = '';
								for(var i=0;i<records.length;i++){
									if(i == 0){
										userIds += records[i].id;
									}else{
										userIds += ','+records[i].id;
									}
								}
								$.ajax({
									type: "get",
									timeout:20000,
									url:  "${ctx}/framework/user/bindRole",
									data:{"deleteIds":userIds,"roleId":'${param.roleId}'},
									success: function(data){
										var msn = ''||i18n[''];
										msn = msn||i18n[data];	
										if(msn == undefined){
											$.messager.alert('提示',i18n.serverError,'info');
										}else if(msn)	{	
											$.messager.alert('提示',msn,'info',function(){$('#bindUserTable').datagrid('reload');$('#addBindUserDialog').dialog('close');});
										}
									},
									error: function(){
										$.messager.alert('提示',i18n.requestError,'error');
									}
								});
							}
						}
					},{
					text:'取消',
						iconCls:'icon-cancel',
						handler:function(){
							$('#addBindUserDialog').dialog('close');
						}}]
		}).dialog('open');
	}
</script>